package cn.wolfcode.luowowo.service.impl;

import cn.wolfcode.luowowo.api.cache.prefix.BasekeyPrefix;
import cn.wolfcode.luowowo.api.cache.prefix.VerifyCodeKeyPrefix;
import cn.wolfcode.luowowo.api.cache.service.IRedisService;
import cn.wolfcode.luowowo.api.cache.service.IVerifyCodeRedisService;
import cn.wolfcode.luowowo.common.exception.DisableException;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class VerifyCodeReidsServiceImpl implements IVerifyCodeRedisService{
    @Autowired
    private IRedisService redisService;

    public void setVerifyRedisCode(String phone, String code) throws DisableException{
        //控制发送短信频率限制
        //VerifyCodeKeyPrefix prefix = new VerifyCodeKeyPrefix("verifyCode", Consts.VERIFY_CODE_VAI_TIME * 60);
      if(!redisService.exists(VerifyCodeKeyPrefix.VERIFY_CODE,phone)){
            //数据库中不存在才发送
            redisService.set(VerifyCodeKeyPrefix.VERIFY_CODE,phone,code);
        }else{
            throw new DisableException("短信已发送,请勿重复操作");
        }
       // redisService.set(VerifyCodeKeyPrefix.VERIFY_CODE,phone,code);
    }

    public String getVerifyCode(BasekeyPrefix verifyCode, String phone) {

        return redisService.get(verifyCode, phone);
    }
}
